;;; test-bag.ss  --  Jens Axel Soegaard

(require "../bag.ss"
         "test-harness.ss")

;;; TEST
; (print-tests 'stop)
(print-tests #t)

(use-bag (instantiate-bag ordered-list-bag@ integers-reverse@))

(let ([A (bag 1 2 3 3)]
      [B (bag 3 4 5)])
  (test (empty? empty))
  (test (union A B)        '((5 . 1) (4 . 1) (3 . 3) (2 . 1) (1 . 1)))
  (test (difference A B)   '((3 . 1) (2 . 1) (1 . 1)))
  (test (intersection A B) '((3 . 1)))
  (test (not (empty? A)))
  (test (member? B 5))
  (test (not (get B 7)))
  (test (subbag? (bag 1 2 2 3) (bag 1 1 2 2 2 3)))
  (test (not (subbag? (bag 1 2 3) (bag 1 2))))
  (test (not (subbag? (bag 1 1 2) (bag 1 2))))
  (test (bag 1 2 3) (bag 2 1 3))
  (test (bag 1 2 3) (insert (bag 1 3) 2))
  (test (bag 1 2)   (remove-all (bag 1 2 2 3 4) '(3 2 4)))
  (test (bag 1 2)   (remove (bag 1 3 2) 3))
  (test (size (bag 1 2 3 3)) 4)
  (test (occurrences (bag 1 1 1 2 2 3) 1) 3)
  (test (occurrences (bag 1 1 1 2 2 3) 4) 0)
  (test (elements (bag 1 1 2 3 3)) '(1 1 2 3 3))
  (test (member? (bag 1 3 4 2) 3))
  (test (not (member? (bag 1 3 4 2) 5)))
  (test (get (bag 1 2 2 2 4) 2) '(2 . 3)))
    
;(use-bag (instantiate-ordered-bag ordered-list-bag@ strings@))
;(elements (intersection (bag "a" "b" "b" "b" "c" "e")
;                        (bag "a" "a" "a" "b" "c" "d")))
